class Solution {
public:
    /**
     * @param word: a non-empty string
     * @param abbr: an abbreviation
     * @return: true if string matches with the given abbr or false
     */
    
    // 练习边界条件！
    bool validWordAbbreviation(string &word, string &abbr) {
        int i = 0;
        int j = 0;
        int l = abbr.length();
        for (; j < l; j++, i++)
        {
            string num = "";
            int num_val = 0;
            if (abbr[j] == '0')
            {
                return false;
            }
            // "a","01":false
            while (j < l && (abbr[j] >= '0' && abbr[j] <= '9'))
            {
                num += abbr[j];
                j++;
            }
            for (int k = 0; k < num.length(); k++)
            {
                num_val += (num[k] - '0') * pow(10, num.length() - k - 1);
            }
            i += num_val;
            if (i > word.length() || word[i] != abbr[j])
            {
                return false;
            }
            // "aa","a2":false
            // "a","1":true
        }
        return true;
    }
};